<template>
  <van-field
    :label="labelFormat"
    :maxlength="maxLength"
    :disabled="disabled"
    v-model="currval"
    @input="updateVal()"
  ></van-field>
</template>


<script>
import { Field } from "vant";
export default {
  name: "my-input",
  props: ["maxLength", "defaultValue", "disabled", "label"],
  data() {
    return {
      currval: ""
    };
  },
  methods: {
    updateVal() {
      this.$emit("update", { label: this.label, val: this.currval });
    }
  },
  computed: {
    labelFormat() {
      return this.label + ":";
    }
  },

  watch: {
    defaultValue: {
      handler(newVal, oldVal) {
        if (this.currval === "") {
          this.currval = newVal;
        }
      },
      immediate: true
    }
  },

  components: {
    [Field.name]: Field
  }
};
</script>

<style lang="less">
</style>
